package q151;

public class Solution {
    public String reverseWords(String s) {
        String[] split = s.split(" ");
        StringBuilder res = new StringBuilder();
        for (int i = split.length -1 ; i >= 0 ; i-- ) {
            if (split[i].trim().length() != 0){
                res.append(split[i].trim() + " ");
            }
        }
        return res.toString().trim();
    }

    public static void main(String[] args) {
        String s = (new Solution()).reverseWords("the   sky is blue");
        System.out.println(s);
    }
}